/*
	发表话题
	@param {cnt}  将要插入的内容
	@param {function} callback

*/
var async = require("async");
var db = require("./config.js").db;

exports.doc_publish_sub = function(cnt, callback) {
    console.log("save**************")
    console.log(cnt)
    let query = `INSERT INTO article(
    author,
    author_id,
    title,
    content,
    img_list,
    is_ess,
    shequ_id
)
VALUES
    (
        ?,?,?,?,?,?,?
    );
`;
    return new Promise(function(resolver, reject) {
        db.query(query, [cnt.author,
            cnt.author_id,
            cnt.title,
            cnt.content,
            cnt.img_list,
            cnt.is_ess,
            cnt.shequ_id
        ], function(err, list) {

            if (err) {
                reject(err);
            };
            db.query(`select last_insert_id() as doc_id`, function(err, data) {
            	if(err){
					 reject(err);
            	}
                resolver({ doc_id: JSON.parse(JSON.stringify(data))[0].doc_id })
            })

        })

    })
}

// db.query('INSERT INTO `article_list`(`id`, `title`, `url`, `class_id`, `created_time`) VALUES (?, ?, ?, ?, ?)',
//           [item.id, item.title, item.url, class_id, created_time], next);